package com.kfm.base.ex;

public class Demo04 {

    public static void main(String[] args) {
        System.out.println("start");
        try{
            // 定义的变量有效范围在 try 代码块里面
            int n = 5 / 0;
            System.out.println("n = " + n);
            "".charAt(10); // StringIndexOutOfBoundsException
            System.out.println("try");
        } catch (NullPointerException ex){
            System.out.println("空指针");
        } catch (ArrayIndexOutOfBoundsException ex){
            System.out.println("数组下标越界");
        } catch (Exception ex){
            System.out.println("exception");
        }

        System.out.println("end");
    }
}
